package _2_函数_运算._6_lambda;

public class LambdaTest {
  public static void printString(String s, Print<String> print) {
    print.print(s);
  }

  public static void main(String[] args) {
    printString("test", System.out::println);
    // 相当于 printString("test", (x) -> { System.out.println(x) })
    //      真正执行的是  ( (x) -> { System.out.println(x)} ).print("test")

    // 而 (x) -> { System.out.println(x) } 会转成匿名类如下所示：
    //

    printString("test", new LambdaTest$$Lambda$1());
  }

  private static void lambda$main$0(String x) {
    System.out.println(x);
  }

  static final class LambdaTest$$Lambda$1 implements Print {
    public void print(Object obj) {
      LambdaTest.lambda$main$0((String) obj);
    }
    private LambdaTest$$Lambda$1() {
    }
  }

}

@FunctionalInterface
interface Print<T> {
  void print(T x);
}